package yartiss.engine.simulation;


public class SimulationStatistics {
	private boolean isFailed;
	private boolean isFinished;
	private double failureCount;
	private double finishedCount;
	
	private double timePassedWithEmax;
	private double timePassedWithEmin;

	private double deadlinesMissedCount;
	private double deadlinesCount;
	
	
	private double busyPerdiodLength;
	private double idlePeriodLength;
	
	private double simulationDuration;
	private long nbBusyPeriods;
	private long nbIdlePeriods;
	
	private double averageBusyPeriod;
	private double averageIdlePeriod;
	
	private Event lastEvent;
	
	
	/**
	 * @return the simulationDuration
	 */
	public double getSimulationDuration() {
		return simulationDuration;
	}
	/**
	 * @param simulationDuration the simulationDuration to set
	 */
	public void setSimulationDuration(double simulationDuration) {
		this.simulationDuration = simulationDuration;
	}
	/**
	 * @return the deadlinesMissedCount
	 */
	public double getDeadlinesMissedCount() {
		return deadlinesMissedCount;
	}
	/**
	 * @param deadlinesMissedCount the deadlinesMissedCount to set
	 */
	public void setDeadlinesMissedCount(double deadlinesMissedCount) {
		this.deadlinesMissedCount = deadlinesMissedCount;
	}
	/**
	 * @return the deadlinesCount
	 */
	public double getDeadlinesCount() {
		return deadlinesCount;
	}
	/**
	 * @param deadlinesCount the deadlinesCount to set
	 */
	public void setDeadlinesCount(double deadlinesCount) {
		this.deadlinesCount = deadlinesCount;
	}
	
	
	/**
	 * @return the failureCount
	 */
	public double getFailureCount() {
		return failureCount;
	}
	/**
	 * @param failureCount the failureCount to set
	 */
	public void setFailureCount(double failureCount) {
		this.failureCount = failureCount;
	}
	/**
	 * @return the finishedCount
	 */
	public double getFinishedCount() {
		return finishedCount;
	}
	/**
	 * @param finishedCount the finishedCount to set
	 */
	public void setFinishedCount(double finishedCount) {
		this.finishedCount = finishedCount;
	}
	
	
	/**
	 * @return the isFailed
	 */
	public boolean isFailed() {
		return isFailed;
	}
	/**
	 * @param isFailed the isFailed to set
	 */
	public void setFailed(boolean isFailed) {
		this.isFailed = isFailed;
	}
	/**
	 * @return the isFinished
	 */
	public boolean isFinished() {
		return isFinished;
	}
	/**
	 * @param isFinished the isFinished to set
	 */
	public void setFinished(boolean isFinished) {
		this.isFinished = isFinished;
	}
	/**
	 * @return the busyPerdiodLength
	 */
	public double getBusyPerdiodLength() {
		return busyPerdiodLength;
	}
	/**
	 * @param busyPerdiodLength the busyPerdiodLength to set
	 */
	public void setBusyPerdiodLength(double busyPerdiodLength) {
		this.busyPerdiodLength = busyPerdiodLength;
	}
	
	/**
	 * @return the nbBusyPeriods
	 */
	public long getNbBusyPeriods() {
		return nbBusyPeriods;
	}
	/**
	 * @param nbBusyPeriods the nbBusyPeriods to set
	 */
	public void setNbBusyPeriods(long nbBusyPeriods) {
		this.nbBusyPeriods = nbBusyPeriods;
	}
	
	/**
	 * @return the idlePeriodLength
	 */
	public double getIdlePeriodLength() {
		return idlePeriodLength;
	}
	/**
	 * @param idlePeriodLength the idlePeriodLength to set
	 */
	public void setIdlePeriodLength(double idlePeriodLength) {
		this.idlePeriodLength = idlePeriodLength;
	}
	
	/**
	 * @return the nbIdlePeriods
	 */
	public long getNbIdlePeriods() {
		return nbIdlePeriods;
	}
	/**
	 * @param nbIdlePeriods the nbIdlePeriods to set
	 */
	public void setNbIdlePeriods(long nbIdlePeriods) {
		this.nbIdlePeriods = nbIdlePeriods;
	}
	
	/**
	 * @return the timePassedWithEmax
	 */
	public double getTimePassedWithEmax() {
		return timePassedWithEmax;
	}
	/**
	 * @param timePassedWithEmax the timePassedWithEmax to set
	 */
	public void setTimePassedWithEmax(double timePassedWithEmax) {
		this.timePassedWithEmax = timePassedWithEmax;
	}
	
	
	/**
	 * @return the timePassedWithEmin
	 */
	public double getTimePassedWithEmin() {
		return timePassedWithEmin;
	}
	/**
	 * @param timePassedWithEmin the timePassedWithEmin to set
	 */
	public void setTimePassedWithEmin(double timePassedWithEmin) {
		this.timePassedWithEmin = timePassedWithEmin;
	}
	
	
	
	/**
	 * 
	 * @param statistics
	 */
	public void sum(SimulationStatistics statistics) {
		failureCount 		+= statistics.getFailureCount();
		finishedCount 		+= statistics.getFinishedCount();
		busyPerdiodLength 	+= statistics.getBusyPerdiodLength();
		idlePeriodLength 	+= statistics.getIdlePeriodLength();
		timePassedWithEmax 	+= statistics.getTimePassedWithEmax();
		setTimePassedWithEmin(getTimePassedWithEmin() + statistics.getTimePassedWithEmin());
	}
	
	/**
	 * 
	 * @param nbEntries
	 */
	public void average(int nbEntries){
		failureCount 		*= 100;
		finishedCount  	  	*= 100;
		busyPerdiodLength  	*= 100;
		idlePeriodLength  	*= 100;
		timePassedWithEmax 	*= 100;
		setTimePassedWithEmin(getTimePassedWithEmin() * 100);
		
		failureCount 		/= nbEntries;
		finishedCount  		/= nbEntries;
		busyPerdiodLength  	/= nbEntries;
		idlePeriodLength  	/= nbEntries;
		timePassedWithEmax 	/= nbEntries;
		setTimePassedWithEmin(getTimePassedWithEmin() / nbEntries);
	}
	
	/**
	 * @return the averageBusyPeriod
	 */
	public double getAverageBusyPeriod() {
		return averageBusyPeriod;
	}
	/**
	 * @param averageBusyPeriod the averageBusyPeriod to set
	 */
	public void setAverageBusyPeriod(double averageBusyPeriod) {
		this.averageBusyPeriod = averageBusyPeriod;
	}
	/**
	 * @return the averageIdlePeriod
	 */
	public double getAverageIdlePeriod() {
		return averageIdlePeriod;
	}
	/**
	 * @param averageIdlePeriod the averageIdlePeriod to set
	 */
	public void setAverageIdlePeriod(double averageIdlePeriod) {
		this.averageIdlePeriod = averageIdlePeriod;
	}
	
	
	@Override
	public String toString() {
		return "SimulationStatistics [isFailed=" + isFailed + ", isFinished="
				+ isFinished + ", failureCount=" + failureCount
				+ ", finishedCount=" + finishedCount + ", timePassedWithEmax="
				+ timePassedWithEmax + ", timePassedWithEmin="
				+ timePassedWithEmin + ", deadlinesMissedCount="
				+ deadlinesMissedCount + ", deadlinesCount=" + deadlinesCount
				+ ", busyPerdiodLength=" + busyPerdiodLength
				+ ", idlePeriodLength=" + idlePeriodLength
				+ ", simulationDuration=" + simulationDuration
				+ ", nbBusyPeriods=" + nbBusyPeriods + ", nbIdlePeriods="
				+ nbIdlePeriods + ", averageBusyPeriod=" + averageBusyPeriod
				+ ", averageIdlePeriod=" + averageIdlePeriod + "]";
	}
	/**
	 * @return the lastEvent
	 */
	public Event getLastEvent() {
		return lastEvent;
	}
	/**
	 * @param lastEvent the lastEvent to set
	 */
	public void setLastEvent(Event lastEvent) {
		this.lastEvent = lastEvent;
	}
	
	
	
	
	
	
	
	
	
}
